package com.ruoyi.miniapp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.log.annotation.Log;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.miniapp.domain.TMiniCategory;
import com.ruoyi.miniapp.service.ITMiniCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 运动分类管理Controller
 * 
 * @author ruoyi
 * @date 2025-07-15
 */
@RestController
@RequestMapping("/miniapp/category")
public class TMiniCategoryController extends BaseController
{
    @Autowired
    private ITMiniCategoryService tMiniCategoryService;

    /**
     * 查询运动分类管理列表
     */
    @PreAuthorize("@ss.hasPermi('miniapp:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMiniCategory tMiniCategory)
    {
        startPage();
        List<TMiniCategory> list = tMiniCategoryService.selectTMiniCategoryList(tMiniCategory);
        return getDataTable(list);
    }

    /**
     * 导出运动分类管理列表
     */
    @PreAuthorize("@ss.hasPermi('miniapp:category:export')")
    @Log(title = "运动分类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TMiniCategory tMiniCategory)
    {
        List<TMiniCategory> list = tMiniCategoryService.selectTMiniCategoryList(tMiniCategory);
        ExcelUtil<TMiniCategory> util = new ExcelUtil<TMiniCategory>(TMiniCategory.class);
        util.exportExcel(response, list, "运动分类管理数据");
    }

    /**
     * 获取运动分类管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('miniapp:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tMiniCategoryService.selectTMiniCategoryById(id));
    }

    /**
     * 新增运动分类管理
     */
    @PreAuthorize("@ss.hasPermi('miniapp:category:add')")
    @Log(title = "运动分类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMiniCategory tMiniCategory)
    {
        return toAjax(tMiniCategoryService.insertTMiniCategory(tMiniCategory));
    }

    /**
     * 修改运动分类管理
     */
    @PreAuthorize("@ss.hasPermi('miniapp:category:edit')")
    @Log(title = "运动分类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMiniCategory tMiniCategory)
    {
        return toAjax(tMiniCategoryService.updateTMiniCategory(tMiniCategory));
    }

    /**
     * 删除运动分类管理
     */
    @PreAuthorize("@ss.hasPermi('miniapp:category:remove')")
    @Log(title = "运动分类管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tMiniCategoryService.deleteTMiniCategoryByIds(ids));
    }
}
